/**
 * 用户服务
 * @TransactionAnnotation表示开启事务
 */
export default class RoleService {
    /**
     * 注册用户
     * @param table                 指定表名称
     * @param user                  用户属性
     * @returns {Promise<*>|void}
     *
     */
    //@TransactionAnnotation
    addRoleEntity(entity) {
        return this['session'].save('t_role', entity);
    }

    /**
     * 保存
     * @param table
     * @param userName
     * @returns {*}
     */
    removeRoleEntity(entity) {
        return this['session'].remove('t_role', entity);
    }

    /**
     * 更新
     * @param table
     * @param entity
     * @returns {*}
     */
    updateRoleEntity(entity) {
        return this['session'].update('t_role', entity);
    }

    /**
     * 查询
     * @param table
     * @param start
     * @param size
     * @returns {*}
     */
    listRoleEntities(start, size, keyWord) {
        return new Promise(async (resolve, reject) => {
            try {
                const sql = keyWord ? "WHERE `t_roleName` LIKE '%" + keyWord + "%' " : "" + "ORDER BY t_createAt DESC"
                const rows = await this['session'].query('t_role', sql, [], start, size);
                const count = await this['session'].exeSQL("select count(*)  from t_role " + sql, []);
                resolve({total: count[0]['count(*)'], records: rows});
            } catch (e) {
                reject(e)
            }
        })
    }


}


